package com.example.mobile2032021606163crw0401;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private ImageView ivon;
    private TextView TV;
    private Button btnlightOn;
    private Button btnlightoff;
    private Button btnkaiguan;
    private boolean fanStatus = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnlightOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivon.setImageResource(R.drawable.light_on);
            }
        });
        btnlightoff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivon.setImageResource(R.drawable.light_off);
            }
        });
        btnkaiguan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (fanStatus){
                   ivon.setImageResource(R.drawable.fan_off);
                   fanStatus = false;
                }else {
                    ivon.setImageResource(R.drawable.fan_on);
                    fanStatus = true;
                }
            }
        });
    }

    private void initView() {
        ivon = (ImageView) findViewById(R.id.ivon);
        TV = (TextView) findViewById(R.id.TV);
        btnlightOn = (Button) findViewById(R.id.btnlightOn);
        btnlightoff = (Button) findViewById(R.id.btnlightoff);
        btnkaiguan = (Button)findViewById(R.id.btnkaiguan);
    }
}